public class BeanList {
    public Bean head;
    private int count = 0;

    public void addBean(Position pos) {
        Bean b = new Bean(pos);
        b.next = head;
        head = b;
        count++;
    }

    public boolean removeBean(Position pos) {
        Bean prev = null, curr = head;
        while (curr != null) {
            if (curr.pos.equals(pos)) {
                if (prev == null) head = curr.next;
                else prev.next = curr.next;
                count--;
                return true;
            }
            prev = curr; curr = curr.next;
        }
        return false;
    }

    public boolean hasBean(Position pos) {
        Bean curr = head;
        while (curr != null) {
            if (curr.pos.equals(pos)) return true;
            curr = curr.next;
        }
        return false;
    }

    public int getCount() { return count; }
}